# -*- coding: utf-8 -*-
# @Time    : 2025/7/20 20:53
# @Author  : Z.J. Zhang
# @Email   : zijingzhang@mail.ustc.edu.cn
# @File    : task_manager.py
# @Software: PyCharm
import time

import os
import pandas
import sys

from _logging import logger

# log_csv_path = "%s.log.csv" % (__file__)
csv_encoding = 'gbk'


class ProgressRecorder:
    def __init__(self, log_csv_path: str = None, csv_encoding=csv_encoding):
        if log_csv_path is None:
            log_csv_path = "%s.log.csv" % (sys.argv[0])
        self.log_csv_path = log_csv_path
        self.csv_encoding = csv_encoding

    # @staticmethod
    def write_parameter_and_result_to_csv(self,
                                          data: dict):
        data["timestamp"] = time.time()
        logger.info(data)
        log_df = pandas.DataFrame([data])

        uncertain_kw_args_for_to_csv = {}
        if os.path.exists(self.log_csv_path):
            # raise RuntimeError("请备份或删除原始文件")
            uncertain_kw_args_for_to_csv = {
                "mode": 'a',
                "header": False}
        log_df.to_csv(self.
                      log_csv_path, index=False, encoding=self.csv_encoding,
                      **uncertain_kw_args_for_to_csv, )

    @staticmethod
    def all_call_backs(xk):
        pass
